﻿using AutoMapper;
using HandyControl.Controls;
using IdentityModel.Client;
using ShanNiang.Mvvm.SaveModels;
using ShanNiang.Mvvm.ViewModels;
using ShanNiang.Service.LoginModels.Responses;
using ShanNiang.Service.PackingModels.Responses;
using ShanNiang.Service.PackingModes.Responses;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ShanNiang.Mvvm.Tools
{
    public class AutoMapperConfiguration : Profile
    {
        public AutoMapperConfiguration()
        {
            CreateMap<UserResponse, UserViewModel>().ForMember(d => d.MenuCodes, o => o.Ignore());
            CreateMap<UserViewModel, UserResponse>().ForMember(d => d.MenuCodes, o => o.Ignore());

            CreateMap<UserWorkSummaryResponse, UserViewModel>();
            CreateMap<UserViewModel, UserWorkSummaryResponse>();


            CreateMap<IdsToken, TokenResponse>();
            CreateMap<TokenResponse, IdsToken>();


            CreateMap<ItemResponse, ItemViewModel>();
            CreateMap<ItemViewModel, ItemResponse>();


            CreateMap<BoxCodeResponse, BoxViewModel>().ForMember(d => d.BoxCode, o => o.MapFrom(s => s.Code));
            CreateMap<BoxViewModel, BoxCodeResponse>().ForMember(d => d.Code, o => o.MapFrom(s => s.BoxCode));


            CreateMap<PackingRecordViewModel, PackingRecordResponse>();
            CreateMap<PackingRecordResponse, PackingRecordViewModel>();


            CreateMap<BoxViewModel, BoxModel>();
            CreateMap<BoxModel, BoxViewModel>();

            CreateMap<PalletDetailResponse, PalletViewModel>();
            CreateMap<PalletViewModel, PalletDetailResponse>();

            CreateMap<BoxDetailViewModel, BoxCodeResponse>()
                .ForMember(d => d.Code, o => o.MapFrom(s => s.BoxCode))
                .ForMember(d => d.LastModifiedTime, o => o.MapFrom(s => s.PackedTime));
            CreateMap<BoxCodeResponse, BoxDetailViewModel>()
                .ForMember(d => d.BoxCode, o => o.MapFrom(s => s.Code))
                .ForMember(d => d.PackedTime, o => o.MapFrom(s => s.LastModifiedTime));


            CreateMap<ItemModel, ItemViewModel>();
            CreateMap<ItemViewModel, ItemModel>();

            CreateMap<PackBoxModel, PackBoxViewModel>()
                .ForMember(d => d.SelectedItem, o => o.MapFrom(s => s.CurrentItem))
                .ForMember(d => d.BoxCode, o => o.MapFrom(s => s.BoxCodeSet));
            CreateMap<PackBoxViewModel, PackBoxModel>()
                .ForMember(d => d.CurrentItem, o => o.MapFrom(s => s.SelectedItem))
                .ForMember(d => d.BoxCodeSet, o => o.MapFrom(s => s.BoxCode));


            CreateMap<PackPalletModel, PackPalletViewModel>();
            CreateMap<PackPalletViewModel, PackPalletModel>();


            CreateMap<BottleCodeViewModel, BottleCodeModel>();
            CreateMap<BottleCodeModel, BottleCodeViewModel>();


            CreateMap<WorkerViewModel, PackingUserResponse>();
            CreateMap<PackingUserResponse, WorkerViewModel>();
        }
    }
}
